/**
 * 9. 回文数
 */

class Solution1 {
    public boolean isPalindrome(int x) {
        if (x<0){
            return false;
        }
         int n = 0;
        int tmp = 0;
        int ct = x;
        while(ct != 0){
            n = ct%10;
            tmp = tmp*10+n;
            ct /=10;
        }

        if (tmp == x){
            return true;
        }else{
            return false;
        }
    }
}

/**
 * 13. 罗马数字转整数
 */

class Solution2 {
    public int romanToInt(String s) {
        int[] tmp = new int[s.length()];

        for (int i = 0;i<s.length();i++){
            switch(s.charAt(i)){
                case 'I':
                    tmp[i] = 1;
                    break;
                case 'V':
                    tmp[i] = 5;
                    break;
                case 'X':
                    tmp[i] = 10;
                    break;
                case 'L':
                    tmp[i] = 50;
                    break;
                case 'C':
                    tmp[i] = 100;
                    break;
                case 'D':
                    tmp[i] = 500;
                    break;
                case 'M':
                    tmp[i] = 1000;
                    break;
            }
        }
        int ret = 0;
        for (int i = 0;i<tmp.length;i++){
            if ( (i < tmp.length-1) && tmp[i] < tmp[i+1]){
                tmp[i] =  -tmp[i];
            }
            ret += tmp[i];
        }
        return ret;
    }
}

/**
 * 14. 最长公共前缀
 */
class Solution3 {
    public String longestCommonPrefix(String[] strs) {
        if (strs.length == 0){
            return "";
        }
        String tmp = strs[0];
        for (int i = 1;i<strs.length;i++){
            int j = 0;
            for (;j < tmp.length() && j<strs[i].length();j++ ){
                if (tmp.charAt(j) != strs[i].charAt(j)){
                    break;
                }
            }
            tmp = tmp.substring(0,j);//重新赋值 目前找到的最长共同值
            if (tmp.equals("")){
                return "";
            }
        }
        return tmp;
    }
}


/*class Solution {
    public boolean isValid(String s) {
        if (s.length() == 0){
            return false;
        }
        for (int i  = 0; i<s.length();i++){
            boolean ans = false;
            for (int j = i+1;j<s.length();j++){
                if ((s.charAt(i) == '(') && (s.charAt(j) == ')')){
                    ans = true;
                }else if((s.charAt(i) =='[') && (s.charAt(j) == ']')){
                    ans = true;
                }else if ((s.charAt(i) == '{') && (s.charAt(j) == '}')){
                    ans = true;
                }
            }
        }
        return ans;

    }
}*/

/**
 * 27. 移除元素
 */

class Solution4 {
    public int removeElement(int[] nums, int val) {
        if (nums.length == 0 || nums == null){
            return 0;
        }
        int j = 0;
        for (int i = 0;i<nums.length;i++){
            if (nums[i] != val){
                nums[j] = nums[i];
                j++;
            }
        }
        return j;
    }
}